<#include '/admin/header.html' > 
<div class="main">
	<div style="display: block;" class="searchAdvanced">
		<input id="Advanced" name="Advanced" type="hidden" value="0" />
		<table width="98%" border="0" cellspacing="0" cellpadding="8">
			<tr>
				<td width="80">
					按订单周期：
				</td>
				<td width="70" >
					<select id="cycle_type" onchange="statistics_mode(this.value)" >
						<option value="1">按照月统计</option>
						<option value="0">按照年统计</option>
					</select>
				</td>
				<td width="70" >
					<select id="year">
					</select>
				</td>
				<td width="70" >
					<select id="month">
					</select>
				</td>
				<td width="200" style="text-align: center;">
					<a id="search_statis" class="button blueButton"  href="javascript:void(0);">开始搜索</a>
				</td>
				<td></td>
			</tr>
		</table>
	</div>
	<div class="clear height10"></div>
	
	<div class="input">
		<div style="display: block;" class="goods_input">
			<div class="contentTab">
				<ul class="tab">
					<li class="contentTabS">退款统计</li> 
				</ul>
			</div>
			
			<div class="shadowBoxWhite wf100 whiteBox">
				<div class="text">
					<div class="tab-page">
						<div class="tab-panel">
							<table class="form-table" style="width: 100%;">
								<tr>
									<td>
										<div id="container" style="width:95%;min-width: 310px; height: 300px; margin: 0 auto">
										</div>
									</td>
								</tr>
							</table>

							
						</div>
					</div>
				</div>
			</div>
			
		</div>
	</div>
	<div class="clear height10"></div>
	
	
</div>
<script type="text/javascript">
var cycle=null;

$(function(){
   var cycle_type = $("#cycle_type :selected").val();
   moneyHighcharts("月");
   var d = new Date()
   saleMoney(cycle_type,d.getFullYear(),d.getMonth() + 1)
});


// 生成图表
function moneyHighcharts(obj){
	sale_money = new Highcharts.Chart({
        chart: {
            type: 'line',
            renderTo: 'container'
        },
        title: {
            text: '退款金额统计（'+obj+")"
        },
        xAxis: {
            categories: ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31']
        },
        yAxis: {
            title: {
                text: '金额 (￥)'
            },
            labels:{
            	formatter: function () {
                    return this.value + '￥';
                }
            }
        },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },
        credits: {  
            enabled: false // remove high chart logo hyper-link  
        }, 
        series: [{
            name: "本"+obj,
        }]
    });
}

function saleMoney(cycle_type,year,month){
	var this_type = $("#this_type").val();
	
	if(cycle_type!=this_type){
		if(cycle_type==1){					//判断按哪个周期显示数据
			moneyHighcharts('月');					
			//$("#this_type").val(cycle_type);
		}else{
			moneyHighcharts('年');
			//$("#this_type").val(cycle_type);
		}
	}
	
	jQuery.getJSON("${ctx}/shop/admin/orderReturnedStatistics/returned-statistics-json.do",{cycle_type:cycle_type,year:year,month:month}, function(data) {
		sale_money.series[0].setData(data.message); 
	});
	
	if(cycle_type==1){	
		if(month==1){
			year = year-1;
			month = 12;
		}else{
			month = month-1;
		}
	}else{
		year = year-1;
	}
	
	//jQuery.getJSON("${ctx}/shop/admin/orderReturnedStatistics/returned-statistics-json.do",{cycle_type:cycle_type,year:year,month:month}, function(data) {  
		//sale_money.series[1].setData(data.message); 
	//});
}
<!--data -->
$(function() {
	var currentYear = new Date().getFullYear();
	var historyYear = currentYear-10;
	
	var currentmonth = new Date().getMonth();
	currentmonth+=1;
	for(var i=0;i<20;i++){
		if(currentYear==historyYear){
			$("#year").append("<option value='"+historyYear+"' selected='selected' >"+historyYear+"年</option>" );
		}else{
			$("#year").append("<option value='"+historyYear+"' >"+historyYear+"年</option>" );
		}
		historyYear++;
	}
	
	for(var i=1;i<=12;i++){
		if(currentmonth==i){
			$("#month").append("<option value='"+i+"' selected='selected' >"+i+"月</option>" );
		}else{
			$("#month").append("<option value='"+i+"' >"+i+"月</option>" );
		}
	}
	

	$("input[type=text]").attr("autocomplete", "off");
	
	$("#search_statis").click(function(){
		refresh_data();
	})
		
});
function statistics_mode(mode_value){
	if(mode_value==1){
		$("#month").show();
	}else{
		$("#month").hide();
	}
	refresh_data();
}
function refresh_data(){
	
	var cycle_type = $("#cycle_type :selected").val();
	var year = $("#year :selected").val();
	var month = $("#month :selected").val();
	//下单金额
	saleMoney(cycle_type,year,month);
}
</script>